package com.csc531.adapters;

import java.util.ArrayList;

import com.csc531.DataTypes.Course;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

/**
 * @author Javier Figueroa
 */
public abstract class ExpandableListAdapter extends BaseExpandableListAdapter 
{
	protected ArrayList<Course> _courses;
	private Context _callerClassContext;
	
	public ExpandableListAdapter(Context context)
	{
		_callerClassContext = context;
		_courses = new ArrayList<Course>();
	}

    public abstract Object getChild(int groupPosition, int childPosition);
 
    public long getChildId(int groupPosition, int childPosition)
    {
        return childPosition;
    }

    public abstract int getChildrenCount(int groupPosition);

    public TextView getGenericView() 
    {
        // Layout parameters for the ExpandableListView
        AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, 64);

        TextView textView = new TextView(_callerClassContext);
        textView.setLayoutParams(lp);
        // Center the text vertically
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
        // Set the text starting position
        textView.setPadding(36, 0, 0, 0);
        return textView;
    }

    public abstract View getChildView(int groupPosition, int childPosition, boolean isLastChild,
            View convertView, ViewGroup parent);

    public abstract Object getGroup(int groupPosition);

    public abstract int getGroupCount();

    public long getGroupId(int groupPosition) 
    {
        return groupPosition;
    }

    public abstract View getGroupView(int groupPosition, boolean isExpanded, View convertView,
            ViewGroup parent);

    public boolean isChildSelectable(int groupPosition, int childPosition) 
    {
        return true;
    }

    public boolean hasStableIds() 
    {
        return true;
    }
}